#!/bin/bash

function rootfs_install()
{
	echo "[$(basename $0)] ${FUNCNAME} $@"

	local TMPROOTFS=tmprootfs
	mkdir -p ${TMPROOTFS}/etc/udev/rules.d/
	mkdir -p ${TMPROOTFS}/opt/rk/

	cp ./gpio.sh                            ${TMPROOTFS}/opt/rk/
	cp ./RKPE3NX1_P3767_gpio_conf.txt       ${TMPROOTFS}/opt/rk/gpio_conf.txt
	cp ./RKPE3NX1_70-persistent-net.rules   ${TMPROOTFS}/etc/udev/rules.d/70-persistent-net.rules

	local TMPROOTFS_PATH=$(abs_path "${TMPROOTFS}")
	local TMPROOTFS_PATH_LEVEL=$(abs_path_level "${TMPROOTFS_PATH}")
	traverse ${TMPROOTFS_PATH} traverse_filter_none 0 traverse_exec_install ${TMPROOTFS_PATH_LEVEL} ${L4T_TOP}/rootfs
	rm -rf ${TMPROOTFS}
}

function rootfs_uninstall()
{
	echo "[$(basename $0)] ${FUNCNAME} $@"

	sudo_cmd "rm -rf ${L4T_TOP}/rootfs/etc/udev/rules.d/70-persistent-net.rules \
					 ${L4T_TOP}/rootfs/opt/rk"
}

#############################################################

if [[ $# -le 0 ]]; then
	exit 0
fi

case $1 in
	"install" )
		rootfs_install
		;;
	"uninstall" )
		rootfs_uninstall
		;;
esac
